<?php
// +----------------------------------------------------------------------
// | OneThink [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.onethink.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: 麦当苗儿 <zuojiazi@vip.qq.com> <http://www.zjzit.cn>
// +----------------------------------------------------------------------

namespace Help\Widget;

use Think\Action;

/**
 * Class CooperateWidget  合作过的小伙伴
 * @package Help\Widget
 * @author:xjw129xjt xjt@ourstu.com
 */
class CooperateWidget extends Action
{

    /* 显示指定分类的同级分类或子分类列表 */
    public function lists($uid)
    {
        $uid = intval($uid) ? intval($uid) : is_login();
        $works = D('Help')->where(array('uid' => $uid, 'status' => 1))->field('id')->select();
        $ids = getSubByKey($works, 'id');
        $list_my = D('HelpAttend')->where(array('help_id' => array('in', $ids),'status'=>1))->field('uid')->select();
        $uids = getSubByKey($list_my, 'uid');

        $attend_help_id = D('HelpAttend')->where(array('uid'=>$uid,'status'=>1))->field('help_id')->select();
        $attend_help_ids = getSubByKey($attend_help_id, 'help_id');
        $list_uid = D('Help')->where(array('id' => array('in', $attend_help_ids),'status'=>1))->field('uid')->select();
        $uids_attend = getSubByKey($list_uid, 'uid');

        $uids = array_merge($uids,$uids_attend);
        $uids = array_unique($uids);
        shuffle($uids);
        $uids = array_slice($uids,0,20);
        $users = array();
        foreach($uids as $v){
            $users[] = query_user(array('uid', 'username', 'nickname', 'space_url', 'space_link', 'avatar64','avatar128', 'rank_html', 'signature'), $v);
        }
        $this->assign('users',$users);
        $this->display('Widget/cooperate');

    }


}
